﻿using mscook.core.domain;
using mscook.core.services;
using mscook.mvc.core;
using mscook.mvc.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mscook.mvc.Areas.weblogin.Controllers
{
    [UserAuthorizeAttribute(Roles = "admin")]
    public class AboutUsController : BaseController
    {
        private IAboutUsService iAboutUsService;
        private ILoginUserService iLoginUserService;
        public AboutUsController(IAboutUsService iAboutUsService, ILoginUserService iLoginUserService)
            : base(iLoginUserService)
        {
            this.iLoginUserService = iLoginUserService;
            this.iAboutUsService = iAboutUsService;
        }
        //
        // GET: /weblogin/AboutUs/

        public ActionResult Index(string nowPageNum, string per = "")
        {
            PageBreakHelper pageHelper = new PageBreakHelper();
            pageHelper.Init(nowPageNum, per);
            long total = 0;
            IList<AboutUs> aboutUsList = iAboutUsService.SelectPageList(pageHelper.Start, pageHelper.PerValue, out total);
            pageHelper.SetViewDataKeys(ViewData, ViewBag, total);
            InitNavBar();
            return View(aboutUsList);
        }

        //
        // GET: /weblogin/AboutUs/Details/5

        public ActionResult Details(string id)
        {
            return View();
        }

        //
        // GET: /weblogin/AboutUs/Add

        public ActionResult Add()
        {
            return View();
        }

        //
        // POST: /weblogin/AboutUs/Add

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Add(AboutUs AboutUs)
        {
            if (ModelState.IsValid)
            {
                iAboutUsService.SaveOrUpdate(AboutUs);
                return RedirectToIndex();
            }
            return View();
        }

        //
        // GET: /weblogin/AboutUs/Edit/5
         [HttpGet]
        public ActionResult Edit(string id)
        {
            AboutUs AboutUs = iAboutUsService.Get(id);
            if (AboutUs != null)
            {
                return View(AboutUs);
            }
            return RedirectToIndex();
        }

        //
        // POST: /weblogin/AboutUs/Edit/5

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult EditPost(AboutUs AboutUs)
        {

            if (ModelState.IsValid)
            {
                UpdateModel(AboutUs);
                iAboutUsService.SaveOrUpdate(AboutUs);
                return RedirectToIndex();
            }
            return View();
        }

        //
        // GET: /weblogin/AboutUs/Delete/

        public ActionResult Delete(string id)
        {
            iAboutUsService.Delete(id);
            return RedirectToIndex();
        }

    }
}
